package cn.llyong.rpc.client.proxy;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

/**
 * @description: 代理工厂类
 * @author: lvyong
 * @date: 2020年06月28日 11:27
 */
@Component
public class RpcProxyFactoryBean<T> implements FactoryBean<T> {

    private Class<T> interfaceClass;

    public RpcProxyFactoryBean() {
    }

    public RpcProxyFactoryBean(Class<T> interfaceClass) {
        this.interfaceClass = interfaceClass;
    }

    public Class<T> getInterfaceClass() {
        return interfaceClass;
    }

    public void setInterfaceClass(Class<T> interfaceClass) {
        this.interfaceClass = interfaceClass;
    }

    @Override
    public T getObject() throws Exception {
        return (T) new RpcInvoker().newProxyInstance(interfaceClass);
    }

    @Override
    public Class<?> getObjectType() {
        return interfaceClass;
    }

    /**
     * 单例模式
      */
    @Override
    public boolean isSingleton() {
        return true;
    }

}